<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head th:include="common/_header :: header">
</head>

<body>
<div style="margin-left: 15px;margin-right: 15px;">
    <form method="post" onsubmit="return false;" id="from-province-update">
        <div class="form-group">
            <label for="id">编号</label>
            <input class="form-control" type="text" id="id" name="id" readonly th:value="${province.id}">
        </div>
        <div class="form-group">
            <label for="name">省名</label>
            <input class="form-control" type="text" id="name" name="name" readonly th:value="${province.name}">
        </div>
        <div class="form-group">
            <label for="area">大区</label>
            <input class="form-control" type="text" id="area" name="area" th:value="${province.area}">
        </div>
        <div class="form-group">
            <label for="priority">权重</label>
            <input class="form-control" type="text" id="priority" name="priority" th:value="${province.priority}">
        </div>
        <div class="form-group">
            <label for="status">状态</label>
            <div class="form-control" id="status">
                <label class="lyear-radio radio-inline radio-primary">
                    <input type="radio" name="status" value="1" id="enable_status"><span>启用</span>
                </label>
                <label class="lyear-radio radio-inline radio-primary">
                    <input type="radio" name="status" value="2" id="disable_status"><span>不启用</span>
                </label>
            </div>
        </div>
        <div class="form-group">
            <button class="btn btn-primary" type="submit" id="form-submit">提交</button>
        </div>
    </form>
</div>

<script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
<script th:src="@{/js/layer/layer.js}"></script>

<script type="text/javascript">
    $(function () {
        // 初始化表示状态的单选按钮的状态
        let status = [[${province.status}]];
        if(status == 1){
            $("#enable_status").prop("checked","checked")
        }else {
            $("#disable_status").prop("checked","checked")
        }

        //提交表单
        $("#form-submit").on('click',function () {
            $.ajax({
                type:"post",
                dataType:"json", //预期服务器端返回的数据的类型
                url:"modifyProvince",
                data:$("#from-province-update").serialize(),
                success:function (res) {
                    layer.alert(res.msg, {
                        skin: 'layui-layer-lan' //样式类名
                        ,closeBtn: 0
                        ,anim: 4 //动画类型
                    }, function(){
                        let index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index); //关闭当前页
                        window.parent.location.reload();//刷新父页面
                    });
                }
            });
        })
    });
</script>
</body>
</html>